package com.business_clean.viewmodel.request

import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import com.business_clean.app.App
import com.business_clean.app.config.Constant
import com.business_clean.app.network.NetUrl
import com.business_clean.data.mode.classes.ClassesDetailEntity
import com.business_clean.data.mode.classes.ClassesEntity
import com.business_clean.data.mode.classes.ClassesListEntity
import me.hgj.mvvmhelper.base.BaseViewModel
import me.hgj.mvvmhelper.ext.rxHttpRequest
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class ClassexViewModel : BaseViewModel() {
    //全部联系人
    var classManger = MutableLiveData<ClassesEntity>()

    var classesEntity = MutableLiveData<ClassesDetailEntity>()

    var saveClassesState = MutableLiveData<Any>()
    var delClassesState = MutableLiveData<Any>()

    /**
     * 获取全部 常用联系人
     */
    fun requestClassesAll(page: Int, project_uuid: String? = "") {
        rxHttpRequest {
            onRequest = {
                classManger.value = RxHttp.get(NetUrl.GET_CLASSES_ALL)
                    .add("page", page)
                    .add("size", Constant.PAGE_SIZE)
                    .add("project_uuid", if (!TextUtils.isEmpty(project_uuid)) project_uuid else App.appViewModelInstance.userInfo.value?.project?.uuid)
                    .toResponse<ClassesEntity>().await()
            }
        }
    }

    /**
     * 添加常用联系人
     */
    fun requestSaveContact(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                saveClassesState.value = RxHttp.get(NetUrl.SAVE_CLASSES)
                    .addAll(hashMap)
                    .toResponse<Any>().await()
            }
        }
    }

    /**
     * 删除半册
     */
    fun requestDelClasses(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                delClassesState.value = RxHttp.get(NetUrl.DEL_CLASSES)
                    .addAll(hashMap)
                    .toResponse<Any>().await()
            }
        }
    }

    /**
     * 详情
     */
    fun requestClassesDetail(hashMap: HashMap<String, String>) {
        rxHttpRequest {
            onRequest = {
                classesEntity.value = RxHttp.get(NetUrl.GET_CLASSES_DETAIL)
                    .addAll(hashMap)
                    .toResponse<ClassesDetailEntity>().await()
            }
        }
    }
}